home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcr / pcr4_4.lha / DIST / gc / GCmach_dep.c < prev    next >
C/C++ Source or Header  |  1990-04-19  |  7KB  |  173 lines

  1. /* begincopyright
  2.   Copyright (c) 1988,1990 Xerox Corporation. All rights reserved.
  3.   Use and copying of this software and preparation of derivative works based
  4.   upon this software are permitted. Any distribution of this software or
  5.   derivative works must comply with all applicable United States export
  6.   control laws. This software is made available AS IS, and Xerox Corporation
  7.   makes no warranty about the software, its performance or its conformity to
  8.   any specification. Any person obtaining a copy of this software is requested
  9.   to send their name and post office or electronic mail address to:
  10.     PCR Coordinator
  11.     Xerox PARC
  12.     3333 Coyote Hill Rd.
  13.     Palo Alto, CA 94304
  14.     
  15.   Parts of this software were derived from code bearing the copyright notice:
  16.   
  17.   Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
  18.   This material may be freely distributed, provided this notice is retained.
  19.   This material is provided as is, with no warranty expressed or implied.
  20.   Use at your own risk.
  21.   
  22.   endcopyright */
  23.   
  24. # include "xr/GCPrivate.h"
  25. # include <setjmp.h>
  26.  
  27. /*
  28.  * Boehm, March 8, 1990 6:13:16 pm PST
  29.  */
  30.  
  31. /* On register window machines, we need a way to flush the registers. */
  32. # ifdef SPARC
  33. #   include <sun4/trap.h>
  34.     asm("    .globl    _GC_save_regs_in_stack");
  35.     asm("_GC_save_regs_in_stack:");
  36.     asm("    t    0x3   ! ST_FLUSH_WINDOWS");
  37.     asm("    mov    %sp,%o0");
  38.     asm("    retl");
  39.     asm("    nop");
  40. # endif
  41.  
  42.  
  43. /* Routine to mark from registers that are preserved by the C compiler. */
  44. /* This must be ported to every new architecture.  There is a generic   */
  45. /* version at the end, that is likely, but not guaranteed to work       */
  46. /* on your architecture.  Run the test_setjmp program to see whether    */
  47. /* there is any chance it will work.                                    */
  48. /* SPARC version assumes it is called before the stack is marked.       */
  49. GC_mark_regs()
  50. {
  51. #       ifdef RT
  52.       register long TMP_SP; /* must be bound to r11 */
  53. #       endif
  54. #       ifdef VAX
  55.     /* VAX - generic code below does not work under 4.2 */
  56.       /* r1 through r5 are caller save, and therefore     */
  57.       /* on the stack or dead.                            */
  58.       asm("pushl r11");     asm("calls $1,_GC_tl_mark");
  59.       asm("pushl r10");     asm("calls $1,_GC_tl_mark");
  60.       asm("pushl r9");    asm("calls $1,_GC_tl_mark");
  61.       asm("pushl r8");    asm("calls $1,_GC_tl_mark");
  62.       asm("pushl r7");    asm("calls $1,_GC_tl_mark");
  63.       asm("pushl r6");    asm("calls $1,_GC_tl_mark");
  64. #       endif
  65. #       ifdef M68K_SUN
  66.     /*  M68K_SUN - could be replaced by generic code */
  67.       /* a0, a1 and d1 are caller save          */
  68.       /*  and therefore are on stack or dead.   */
  69.     
  70.       asm("subqw #0x4,sp");        /* allocate word on top of stack */
  71.  
  72.       asm("movl a2,sp@");    asm("jbsr _GC_tl_mark");
  73.       asm("movl a3,sp@");    asm("jbsr _GC_tl_mark");
  74.       asm("movl a4,sp@");    asm("jbsr _GC_tl_mark");
  75.       asm("movl a5,sp@");    asm("jbsr _GC_tl_mark");
  76.       /* Skip frame pointer and stack pointer */
  77.       asm("movl d1,sp@");    asm("jbsr _GC_tl_mark");
  78.       asm("movl d2,sp@");    asm("jbsr _GC_tl_mark");
  79.       asm("movl d3,sp@");    asm("jbsr _GC_tl_mark");
  80.       asm("movl d4,sp@");    asm("jbsr _GC_tl_mark");
  81.       asm("movl d5,sp@");    asm("jbsr _GC_tl_mark");
  82.       asm("movl d6,sp@");    asm("jbsr _GC_tl_mark");
  83.       asm("movl d7,sp@");    asm("jbsr _GC_tl_mark");
  84.  
  85.       asm("addqw #0x4,sp");        /* put stack back where it was    */
  86. #       endif
  87.  
  88. #       ifdef M68K_HP
  89.     /*  M68K_HP - could be replaced by generic code */
  90.       /* a0, a1 and d1 are caller save.  */
  91.     
  92.       asm("subq.w &0x4,%sp");    /* allocate word on top of stack */
  93.  
  94.       asm("mov.l %a2,(%sp)"); asm("jsr _GC_tl_mark");
  95.       asm("mov.l %a3,(%sp)"); asm("jsr _GC_tl_mark");
  96.       asm("mov.l %a4,(%sp)"); asm("jsr _GC_tl_mark");
  97.       asm("mov.l %a5,(%sp)"); asm("jsr _GC_tl_mark");
  98.       /* Skip frame pointer and stack pointer */
  99.       asm("mov.l %d1,(%sp)"); asm("jsr _GC_tl_mark");
  100.       asm("mov.l %d2,(%sp)"); asm("jsr _GC_tl_mark");
  101.       asm("mov.l %d3,(%sp)"); asm("jsr _GC_tl_mark");
  102.       asm("mov.l %d4,(%sp)"); asm("jsr _GC_tl_mark");
  103.       asm("mov.l %d5,(%sp)"); asm("jsr _GC_tl_mark");
  104.       asm("mov.l %d6,(%sp)"); asm("jsr _GC_tl_mark");
  105.       asm("mov.l %d7,(%sp)"); asm("jsr _GC_tl_mark");
  106.  
  107.       asm("addq.w &0x4,%sp");    /* put stack back where it was    */
  108. #       endif /* M68K_HP */
  109.  
  110. #       ifdef I386
  111.     /* I386 code, generic code does not appear to work */
  112.       asm("pushl %eax");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  113.       asm("pushl %ecx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  114.       asm("pushl %edx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  115.       asm("pushl %esi");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  116.       asm("pushl %edi");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  117.       asm("pushl %ebx");  asm("call _GC_tl_mark"); asm("addl $4,%esp");
  118. #       endif
  119.  
  120. #       ifdef NS32K
  121.       asm ("movd r3, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
  122.       asm ("movd r4, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
  123.       asm ("movd r5, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
  124.       asm ("movd r6, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
  125.       asm ("movd r7, tos"); asm ("bsr ?_GC_tl_mark"); asm ("adjspb $-4");
  126. #       endif
  127.  
  128. #       ifdef SPARC
  129.       /* generic code will not work */
  130.       GC_save_regs_in_stack();
  131. #       endif
  132.  
  133. #    ifdef RT
  134.         GC_tl_mark(TMP_SP);    /* GC_tl_mark from r11 */
  135.  
  136.         asm("cas r11, r6, r0"); GC_tl_mark(TMP_SP);    /* r6 */
  137.         asm("cas r11, r7, r0"); GC_tl_mark(TMP_SP);    /* through */
  138.         asm("cas r11, r8, r0"); GC_tl_mark(TMP_SP);    /* r10 */
  139.         asm("cas r11, r9, r0"); GC_tl_mark(TMP_SP);
  140.         asm("cas r11, r10, r0"); GC_tl_mark(TMP_SP);
  141.  
  142.         asm("cas r11, r12, r0"); GC_tl_mark(TMP_SP); /* r12 */
  143.         asm("cas r11, r13, r0"); GC_tl_mark(TMP_SP); /* through */
  144.         asm("cas r11, r14, r0"); GC_tl_mark(TMP_SP); /* r15 */
  145.         asm("cas r11, r15, r0"); GC_tl_mark(TMP_SP);
  146. #       endif
  147.  
  148. #     if 0
  149.     /* Generic code                          */
  150.     /* The idea is due to Parag Patel at HP. */
  151.     /* We're not sure whether he would like  */
  152.     /* to be he acknowledged for it or not.  */
  153.     {
  154.         jmp_buf regs;
  155.         register word * i = (word *) regs;
  156.         register word * lim = (word *) (((char *)(regs)) + (sizeof regs));
  157.  
  158.         /* Setjmp on Sun 3s doesn't clear all of the buffer.  */
  159.         /* That tends to preserve garbage.  Clear it.         */
  160.         for (; i < lim; i++) {
  161.             *i = 0;
  162.         }
  163.         (void) _setjmp(regs);
  164.         GC_tl_mark_all(regs, lim);
  165.     }
  166. #     endif
  167.  
  168.       /* other machines... */
  169. #       if !(defined M68K_SUN) && !defined(M68K_HP) && !(defined VAX) && !(defined RT) && !(defined SPARC) && !(defined I386) &&!(defined NS32K)
  170.         --> bad news <--
  171. #       endif
  172. }
  173.